from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d):
        super().__init__(d)

    def get_name(self):
        return "天剑奇缘"

    def game_alert(self):
        self.log_msg("检查是否存在弹窗")
        while True:
            if self.alert_close('./game/img/天剑奇缘/play_alert.png'):
                continue
            if self.alert_close('./game/img/天剑奇缘/alert.png'):
                continue
            if self.alert_close('./game/img/天剑奇缘/alert02.png', 2):
                continue
            break

    def handle_main(self):
        self.log_msg("等待进入游戏")
        self.img_exit('./game/img/天剑奇缘/game_main.png', 100)
        self.log_msg("已进入游戏")

        self.game_alert()
        self.log_msg("点击开始游戏")
        self.img_click('./game/img/天剑奇缘/start.png')

        while not self.check_done():
            self.game_alert()

            self.log_msg("点击通关")
            self.img_click('./game/img/天剑奇缘/play.png')
            self.log_msg("点击确定")
            self.img_click('./game/img/天剑奇缘/play_alert.png')

        #self.d.sleep(2)
#        self.close_game()
        return True
